//
// Created by MikeChen on 2025/4/4.
//


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {

    char str1[128] = "Hello";
    char str2[128] = "Hello";
    char str3[128] = "Hello!";
    char str4[128] = "Hell";

    //strcmp字符串比较，按照ASCII码值一个一个字符比较
    //返回结果是0，表示两个字符串相等
    //返回结果是1，表示字符串1大于字符串2
    //返回结果是-1，表示字符串1小于字符串2
    int val1 = strcmp(str1, str2);
    int val2 = strcmp(str1, str3);
    int val3 = strcmp(str1, str4);

    printf("strcmp:%d\n", val1);
    printf("strcmp:%d\n", val2);
    printf("strcmp:%d\n", val3);

    printf("\n....................\n");
    //strcmp的功能复写
    char *pStr1 = str1;
    char *pStr2 = str2;

    while (*pStr1 == *pStr2) {
        if (*pStr1 == '\0') {
            break;//退出循环
        }
        *pStr1++;
        *pStr2++;
    }
    if (*pStr1 - *pStr2 > 0) {
        printf("字符串str1 > 字符串str2\n");
    } else if (*pStr1 - *pStr2 == 0) {
        printf("字符串str1 = 字符串str2\n");
    } else {
        printf("字符串str1 < 字符串str2\n");
    }
    printf("the end");

    system("read -rsp $'Press enter to continue...\\n'");
    return EXIT_SUCCESS;
}